package com.mikelouis.test.scala.proginscala.chapter12

/**
 * Created by yuazhu on 1/12/2015.
 */
object Rectangle {
  def main(args: Array[String]) {
    val rect = new Rectangle(new Point(1, 1), new Point(10, 10))
    println(rect)
    println("left = " + rect.left)
    println("right = " + rect.right)
    println("width = " + rect.width)
  }
}

class Point(val x: Int, val y: Int)

trait Rectangular {
  def topLeft: Point

  def bottomRight: Point

  def left = topLeft.x

  def right = bottomRight.y

  def width = right - left

  // and many more geometric methods...
}

abstract class Component extends Rectangular {
  // other methods...
}

class Rectangle(val topLeft: Point, val bottomRight: Point) extends Component with Rectangular {
  // other methods...
}